package com.itheima.knowledge.manager.entry;

import com.itheima.knowledge.manager.controller.KnowledgeController;
import com.itheima.knowledge.manager.dao.KnowledgeDao;
import com.itheima.knowledge.manager.domain.Catalog;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Scanner;

public class KnowledgeEntry {
    public static KnowledgeDao kd = new KnowledgeDao();
    static Scanner sc = new Scanner(System.in);
    public static KnowledgeController kc = new KnowledgeController();
    public static void main(String[] args) {
        String know ;
        while (true) {
            ArrayList<Catalog> array = kd.findCatalog();
            System.out.println("-----------欢迎来到知识管理系统-----------");
            Date date = new Date();//当前时间
            String tomorrow ="2021年04月20日";
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
            Date date1 = null;
            try {
                date1 =sdf.parse(tomorrow);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            long times = date1.getTime() - date.getTime();
            String today = sdf.format(date);
            System.out.println("今天是:"+today+"  距离毕业还有:"+(times/(1000*60*60*24))+"天");
            System.out.print("请输入您的选择: ");
            for (int i = 3; i < array.size(); i++) {
                System.out.print(array.get(i).getLogid()+"."+array.get(i).getLogknow()+" ");
            }
            for (int i = 0; i < 3; i++) {
                System.out.print(array.get(i).getLogid()+"."+array.get(i).getLogknow()+" ");
            }
            System.out.println("e.退出");
            String choice = sc.nextLine();
            boolean f1 = true;
            if(choice.equals("e"))
            {
                return;
            }else if(choice.equals("c")){
                addCatalog();
                f1 = false;
            }else if(choice.equals("u")){
                updataCatalog();
                f1 = false;
            }else if(choice.equals("d")){
                deleteCatalog();
                f1 = false;

            }
            for (int i = 3; i < array.size(); i++) {
                if (array.get(i).getLogid() != null && array.get(i).getLogid().equals(choice)) {
                    know = array.get(i).getLogknow();
                    kc.start(know);
                    f1 = false;
                    break;
                }
            }
            if (f1){
                System.out.println("输入有误,请重新输入!");
            }
           // int choice1 = Integer.parseInt(choice);
           /* switch (choice) {
                case "1":
                    //学生管理
                   // Controller StudentController = new Controller("学生","Student");
                   // DAO.flag = "Student";
                   // StudentController.strat();
                    break;
                case "2":
                    //老师管理
                   // Controller  TeacherController = new Controller("老师","Teacher1");
                   // DAO.flag = "Teacher";
                    //TeacherController.strat();
                    break;
                case "3":
                    //退出
                    System.out.println("欢迎下次使用,再见");
                    return;
                default:
                    System.out.println("您的输入有误,请重新输入");
                    break;
            }*/
        }

    }

    public static void deleteCatalog() {
        System.out.println("请输入管理员权限密码:");
        String admin = sc.nextLine();
        if (admin.equals("123456qwe~")){
            //删除
            kc.deleteCatalog();
        }else {
            System.out.println("密码错误!");
        }
    }

    public static void updataCatalog() {
        kc.updataCatalog();
    }

    public static void addCatalog() {
        kc.addCatalog();
    }
}
